#include "../game_server.cpp"
#include "../room.cpp" 
#include "../user.cpp" 
#include "ws_websocket.hpp"

using namespace std;
FASTDO_API void ActionMain(ProtocolC2SEnterRoom *msg, pWsReqCtx ctx, GameServer &game)
{
    auto user = game.getUser(ctx);
    auto room = game.getRoom(msg->id);

    ProtocolS2CEnterRoom rtn;
    if (user)
    {
        auto srcRoom = game.getRoomByUser(user);
        if (!srcRoom && room)
        {
            room->userEnter(user);
            rtn.room = room->toProtocol();
            rtn.ok = true;
        }
    }
    ctx->send(ws::OpCode::dataText, false, rtn.toMixed().json());
}